home *** CD-ROM | disk | FTP | other *** search
/ Merciful 5 / Merciful - Disc 5.iso / software / d / devpac / devpacv2.0a.dms / devpacv2.0a.adf / include / misc / easystart.i
Text File  |  1988-10-06  |  1KB  |  67 lines

  1.  
  2. * some startup code to make a Workbench execute look like the CLI
  3. * based loosely on RKM Vol 1 page 4-36
  4.  
  5. * Include this at the front of your program
  6. * after any other includes
  7. * note that this needs exec/exec_lib.i
  8.  
  9.     IFND    EXEC_EXEC_I
  10.     include    "exec/exec.i"
  11.     ENDC
  12.     IFND    LIBRARIES_DOSEXTENS_I
  13.     include    "libraries/dosextens.i
  14.     ENDC
  15.  
  16.  
  17.     movem.l    d0/a0,-(sp)        save initial values
  18.     clr.l    returnMsg
  19.  
  20.     sub.l    a1,a1
  21.     CALLEXEC FindTask        find us
  22.     move.l    d0,a4
  23.  
  24.     tst.l    pr_CLI(a4)
  25.     beq.s    fromWorkbench
  26.  
  27. * we were called from the CLI
  28.     movem.l    (sp)+,d0/a0        restore regs
  29.     bra    end_startup        and run the user prog
  30.  
  31. * we were called from the Workbench
  32. fromWorkbench
  33.     lea    pr_MsgPort(a4),a0
  34.     CALLEXEC WaitPort        wait for a message
  35.     lea    pr_MsgPort(a4),a0
  36.     CALLEXEC GetMsg            then get it
  37.     move.l    d0,returnMsg        save it for later reply
  38.  
  39. * do some other stuff here RSN like the command line etc
  40.     nop
  41.  
  42.     movem.l    (sp)+,d0/a0        restore
  43. end_startup
  44.     bsr.s    _main            call our program
  45.  
  46. * returns to here with exit code in d0
  47.     move.l    d0,-(sp)        save it
  48.  
  49.     tst.l    returnMsg
  50.     beq.s    exitToDOS        if I was a CLI
  51.  
  52.     CALLEXEC Forbid
  53.     move.l    returnMsg(pc),a1
  54.     CALLEXEC ReplyMsg
  55.  
  56. exitToDOS
  57.     move.l    (sp)+,d0        exit code
  58.     rts
  59.  
  60. * startup code variable
  61. returnMsg    dc.l    0
  62.  
  63. * the program starts here
  64.     even
  65. _main    
  66.  
  67.